﻿//∥∥∥∥∥∥∥∥∥∥∥∥∥∥ICode.name ;
package {
	//
	import flash.display.Sprite ;
	import flash.display.StageAlign ;
	import flash.display.StageScaleMode ;
	import flash.text.TextField ;
	import flash.text.TextFormat ;
	import flash.text.TextFieldAutoSize ;
	import flash.events.Event ;
	import flash.events.IOErrorEvent ;
	import flash.events.ProgressEvent ;
	import flash.net.URLLoader ;
	import flash.net.URLRequest ;
	import ICode.name.ui.NavigateComboBox ;
	import ICode.name.ui.BigBitmapLoader ;
	import ICode.name.net.QueLoader ;
	import fl.controls.ComboBox ;
	//
	public class BitmapTestRoot extends Sprite {
		//
		private var InputWidth = 290 ;
		private var LoaderPosY :int = 29 ;
		//∥∥∥∥∥∥∥∥∥∥∥∥∥∥
		private var m_obInput:ComboBox = new NavigateComboBox () ;
		private var m_arrData:Array = ["data/bigimage.xml","data/small.xml"] ;
		private var m_obLoader:BigBitmapLoader = new BigBitmapLoader ()  ;
		private var m_obText:TextField = new TextField() ;
		//
		//∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥构造函数
		public function BitmapTestRoot(){
			m_obInput .width = InputWidth ;
			m_obLoader.y = LoaderPosY ;
			var obFormat:TextFormat = new TextFormat("宋体",13);
			m_obText.defaultTextFormat = obFormat ;
			m_obText.autoSize = TextFieldAutoSize.LEFT ;
			m_obText.x = InputWidth + 6 ;
			m_obText.text = "Please select a file ;";
			super.addChild(m_obText ) ;
			super.addChild(m_obInput ) ;
			super.addChild(m_obLoader ) ;
			//∥∥∥∥∥∥∥∥∥∥∥∥∥∥..add the data ;
			for(var i:uint = 0 ;i<m_arrData.length ;i++ ){
				m_obInput.addItem({label:m_arrData[i]});
			}
			m_obInput.addEventListener(Event.CHANGE,change_obInput );
			if(stage){
				stage.scaleMode = StageScaleMode.NO_SCALE ;
				stage.align = StageAlign.TOP_LEFT ;
				stage.showDefaultContextMenu = false ;
				stage.addEventListener(Event.RESIZE ,resize_obStage );
				resize_obStage (null ) ;
			}
		}
		//∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥舞台覆盖函数
		private function resize_obStage(e:Event):void {
			if(stage){
				m_obLoader.width = stage.stageWidth ;
				m_obLoader.height = stage.stageHeight - m_obLoader.y ;
			}
		}
		//∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥加载完成函数
		private function complete_obXLoader(e:Event ):void {
			var loader:URLLoader = e.target as URLLoader ;
			loader.removeEventListener(Event.COMPLETE,complete_obXLoader );
			loader.removeEventListener(IOErrorEvent.IO_ERROR ,ioError_obXLoader ) ;
			var xml:XML = XML(e.target.data);
			m_obLoader.addEventListener(Event.COMPLETE,complete_obLoader ) ;
			m_obLoader.addEventListener(ProgressEvent.PROGRESS, progress_obLoader );
			m_obLoader.load(xml );
		}
		//∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥图片完成函数
		private function complete_obLoader(e:Event):void {
			var str:String = "width=" + m_obLoader.cellWidth + "*" + m_obLoader.columns + "=" + m_obLoader.dataWidth + " pixels; ";
			str += "height=" + m_obLoader.cellHeight + "*" + m_obLoader.lines + "=" + m_obLoader.dataHeight + " pixels" ;
			m_obText.text = str ;
		}
		//∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥错误处理函数
		private function ioError_obXLoader(e:IOErrorEvent ):void {} ;
		//∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥图片进度处理函数
		private function progress_obLoader(e:ProgressEvent):void {
			var info:String = QueLoader.getPercent(e.bytesTotal , " of " ) + " , ";
			m_obText.text = info + e.bytesLoaded/10 + " % loaded " ;
		}
		//∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥地址输入函数
		private function change_obInput(e:Event ):void {
			var loader:URLLoader = new URLLoader () ;
			loader.addEventListener(Event.COMPLETE,complete_obXLoader );
			loader.addEventListener(IOErrorEvent.IO_ERROR ,ioError_obXLoader ) ;
			loader.load(new URLRequest (m_obInput.text )) ;
		}
		//∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥
	}
}


